//
//  SinaBaseTableViewController.swift
//  weibo
//
//  Created by liuchao on 16/1/20.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class SinaBaseTableViewController: UITableViewController {

    var isLogin:Bool=false
    
    var visitor:SinaVisitorView?
    
    override func loadView() {
        
        printLog(SinaAccountViewModel.shareInstance.access_token)
        
        isLogin =  SinaAccountViewModel.shareInstance.isLogin
        
        
        if isLogin{
           
             super.loadView()
        }else{
        
             visitor = SinaVisitorView()
            
             visitor?.startAnimation()
            
             setNavigation()
            
             view = visitor
            
            
        
        }
    }
    
    func setNavigation(){
    
        navigationItem.leftBarButtonItem=UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "didRegisterMethod")
        navigationItem.rightBarButtonItem=UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "didLoginMethod")
    }
    
    // 2 一定要实现代理方法
    func didLoginMethod() {
        
        printLog("base 登录")
        
    }
    
    func didRegisterMethod() {
        printLog("base 注册")
        
        // 1.创建视图控制器
        let oauth = SinaOauthViewController()
        // 2 防止到一个nav
        let nav = UINavigationController(rootViewController: oauth)
        // 3 跳转
        presentViewController(nav, animated: true) { () -> Void in
            
        }
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

       
    }



}
